package api

import (
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
	"github.com/zhang201702/zhang"
)

type FontApi struct {
	BaseApi
}

func init()  {
	registerApi("font", func(name string) Api {
		api := &FontApi{BaseApi:*NewBaseApi(name,name)}
		return api
	})
}
func (api *FontApi) Register(s *zhang.ServerGF) {
	api.BaseApi.Register(s)
	s.BindHandler("/font/upload", api.fontUpload)
}

func (api *FontApi) fontUpload(r *ghttp.Request) {
	_, path := uploadFile(r, "/font/")
	if path != "" {
		fontName := r.GetString("fontName")
		font := g.Map{"name": fontName, "path": path}
		_, err := api.service.Insert(font)
		api.Result(font, err, r)
	}
}
